from flask import Flask
from config import DevelopmentConfig
from exts import db,mail,cache
from blueprints.user import bp as user_bp
from blueprints.cms import bp as cms_bp
from blueprints.front import bp as front_bp
from flask_migrate import Migrate
from models import books,user
import commands
import hooks
app = Flask(__name__)

app.config.from_object(DevelopmentConfig)
db.init_app(app)
mail.init_app(app)
migrate = Migrate(app,db)
cache.init_app(app)

app.register_blueprint(user_bp)
app.register_blueprint(cms_bp)
app.register_blueprint(front_bp)

app.cli.command("create-board")(commands.create_board)
app.cli.command("create-book")(commands.create_book)
app.cli.command("add-author-name")(commands.add_book_author_name)
app.cli.command("create-permission")(commands.create_permission)
app.cli.command("create-roles")(commands.create_role)
app.cli.command("add-desc")(commands.add_desc)
app.cli.command("add-emp")(commands.add_emp)
app.cli.command("add-user")(commands.add_user)
app.before_request(hooks.get_current_user)

if __name__ == '__main__':
    app.run()
